package com.sk.rpcAssistNetty.io.protocol;

import com.alibaba.fastjson.JSON;
/**
 * description：json 可读性强，但是序列化速度慢，体积大
 *
 * @author 孙文斌
 * @Date: 2021/3/22 14:23
 */
public class JsonSerialization implements SerializeProtocol {

    public static JsonSerialization getInstance() {
        return new JsonSerialization();
    }
    @Override
    public String getCode() {
        return "p2";
    }

    @Override
    public <T> byte[] serialize(T object) {
        byte[] bytes = JSON.toJSONBytes(object);
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {
        return JSON.parseObject(bytes, clazz);
    }
}
